package com.live.play;

import com.blankj.utilcode.util.ThreadUtils;
import com.tencent.qgame.animplayer.AnimConfig;
import com.tencent.qgame.animplayer.AnimView;
import com.tencent.qgame.animplayer.inter.IAnimListener;

import org.jetbrains.annotations.NotNull;

public class Mp4AnimUtils {


    public static void playAssets(String path, AnimView playView, OnPlayCallback callback, boolean fixed) {
        playView.setAnimListener(new IAnimListener() {
            @Override
            public boolean onVideoConfigReady(@NotNull AnimConfig animConfig) {
                return true;
            }

            @Override
            public void onVideoStart() {
                ThreadUtils.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        if (callback != null) {
                            callback.onStart();
                        }
                    }
                });
            }

            @Override
            public void onVideoRender(int i, @org.jetbrains.annotations.Nullable AnimConfig animConfig) {

            }

            @Override
            public void onVideoComplete() {
                ThreadUtils.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        if (callback != null) {
                            callback.onVideoComplete();
                        }
                    }
                });
            }

            @Override
            public void onVideoDestroy() {

            }

            @Override
            public void onFailed(int i, @org.jetbrains.annotations.Nullable String s) {

            }
        });
        playView.startPlay(playView.getContext().getAssets(), path);
    }

    public interface OnPlayCallback {
        void onStart();

        default void onFailed() {
        }

        void onVideoComplete();
    }
}
